<template>
  <div id="dashboard">
    <!-- 仪表页头部 -->
    <device-header :info="HeadObj"></device-header>

    <!-- 设备概览、监控、公告 -->
    <div class="second">
      <div class="de-left">
        <MyEquipment></MyEquipment>
      </div>

      <div class="de-right">
        <!-- 公告 -->
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>公告</span>
            <el-tooltip content="1001010100100" placement="top" effect="dark">
              <i class="iconfont icon-askoutline"></i>
            </el-tooltip>
          </div>
          <div class="gonggao">
            <div class="g-con">
              <div>
                <i class="iconfont icon-info"></i>
                <span>senseCAP V3 02020-02-13 14:28:07</span>
              </div>
              <div>
                <i class="iconfont icon-info"></i>
                <span>senseCAP V3 02020-02-13 14:28:07</span>
              </div>
            </div>
          </div>
        </el-card>
      </div>
    </div>

    <!-- 空气湿度、光照、气压、土壤湿度 -->
    <div class="tubiao">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>空气湿度</span>
        </div>
        <div class="chartArea" ref="air"></div>
      </el-card>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>光照</span>
        </div>
        <div class="chartArea" ref="beam"></div>
      </el-card>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>气压</span>
        </div>
        <div class="chartPressure" ref="pressure"></div>
      </el-card>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>土壤湿度</span>
        </div>
        <div class="chartArea" ref="soil"></div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { $sensorCount } from '@/api/index.js'
import MyEquipment from '../../components/MyEquipment.vue'
import DeviceHeader from '../../components/DeviceHeader.vue'
export default {
  name: 'dashboarddata',
  data () {
    return {
      HeadObj: {
        type: '',
        text: '仪表盘',
        content: '设备概览和传感数据可视化。'
      }
    }
  },
  components: {
    MyEquipment, DeviceHeader
  },
  mounted () {
    this.getSensor()
  },
  methods: {
    getSensor () {
      $sensorCount().then((res) => {
        console.log(149, res)
        this.Drow(res.data.data)
      })
    },
    Drow (data) {
      console.log(this.$refs.air)
      const myChart1 = this.$echarts.init(this.$refs.air)
      const myChart2 = this.$echarts.init(this.$refs.beam)
      const myChart3 = this.$echarts.init(this.$refs.pressure)
      const myChart4 = this.$echarts.init(this.$refs.soil)
      const option1 = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: data.air,
            type: 'line',
            smooth: true
          }
        ]
      }
      const option2 = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: data.beam,
            type: 'bar'
          }
        ]
      }
      const option3 = {
        legend: {
          top: 'bottom'
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        series: [
          {
            name: 'Nightingale Chart',
            type: 'pie',
            radius: [10, 70],
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: data.pressure
          }
        ]
      }
      const option4 = {
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: data.soil,
            type: 'line',
            smooth: true
          }
        ]
      }
      myChart1.setOption(option1)
      myChart2.setOption(option2)
      myChart3.setOption(option3)
      myChart4.setOption(option4)
    }
  }
}
</script>

<style scoped lang="less">
#dashboard .first .card-top {
  margin-bottom: 10px;
  span {
    font-size: 13px;
    color: #666;
  }
}
.icon-askoutline {
  color: rgb(194, 194, 194);
  margin-left: 3px;
}
#dashboard .second {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  .clearfix {
    span {
      font-size: 14px;
      font-weight: bold;
    }
  }
  .de-left {
    width: 77.3%;
    margin-right: 10px;
    flex: 1;
  }
  .de-right {
    width: 22%;
    .box-card {
      height: 203px;
    }
  }
}
.de-right {
  .gonggao {
    .icon-info {
      color: rgb(16, 218, 9);
      font-weight: bold;
    }
    .g-con {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      font-size: 13px;
      div {
        width: 100%;
        margin-top: 15px;
      }
    }
  }
}
.tubiao {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  .box-card {
    width: 49.5%;
    margin-bottom: 10px;
    .chartArea {
      height: 200px;
      // display: flex;
      // justify-content: center;
      // align-items: center;
    }
    .chartPressure {
      height: 200px;
    }
  }
}
</style>
